<template>
  <div class="app-container">
    <div>
      <el-input
        placeholder="请输入内容"
        v-model="queryParams.sql"
        clearable
        style="width: 18%"
      >
      </el-input>
      <el-button type="primary" @click="getList" icon="el-icon-searchsousuo"
        >搜索</el-button
      >
      <el-button type="primary" @click="chumenzheng">出门证</el-button>
    </div>
    <div class="content">
      <el-table
        :data="tableData"
        border
        style="width: 100%; height: 100%"
        @row-dblclick="handleRowDblClick"
      >
        <el-table-column prop="gid" label="编号" width="90px" sortable>
        </el-table-column>
        <el-table-column prop="ddbh" label="订单号" sortable> </el-table-column>
        <el-table-column prop="czbh" label="称重编号" width="200px" sortable>
        </el-table-column>
        <el-table-column prop="card_id" label="卡号" sortable>
        </el-table-column>
        <el-table-column prop="chehao" label="车号" sortable> </el-table-column>
        <el-table-column prop="wlmc" label="物料名称" width="150px" sortable>
        </el-table-column>
        <el-table-column prop="jcsj" label="进场时间" width="150px" sortable>
        </el-table-column>
        <el-table-column prop="dbh" label="进场地磅" sortable>
        </el-table-column>
        <el-table-column prop="chsj" label="出厂时间" width="150px" sortable>
        </el-table-column>
        <el-table-column prop="dbh2" label="出厂地磅" sortable>
        </el-table-column>
        <el-table-column prop="gbzt" label="过磅状态" sortable>
        </el-table-column>
        <el-table-column prop="tc" label="退车" sortable> </el-table-column>
        <el-table-column prop="nw_wx" label="内外销" sortable>
        </el-table-column>
        <el-table-column prop="bzwm" label="包装物名" sortable>
        </el-table-column>
        <el-table-column prop="fksj" label="发卡时间" sortable>
        </el-table-column>
      </el-table>

      <el-dialog title="详细信息处理" :visible.sync="dialogVisible" width="90%">
        <el-form label-width="100px" :inline="true">
          <el-row :gutter="20">
            <!-- 第一行 -->
            <el-col :span="3">
              <el-form-item label="车号">
                <el-input v-model="selectedRow.chehao"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="供应商编号">
                <el-input v-model="selectedRow.gysbh"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="供应商名称">
                <el-input v-model="selectedRow.gysdm"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="公司编号">
                <el-input v-model="selectedRow.gsbh"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="公司名称">
                <el-input v-model="selectedRow.gsmc"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="物料编号">
                <el-input v-model="selectedRow.wlbh"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="物料名称">
                <el-input v-model="selectedRow.wlmc"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="仓库编号">
                <el-input v-model="selectedRow.ckbh"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <!-- 第二行 -->
            <el-col :span="3">
              <el-form-item label="仓库名称">
                <el-input v-model="selectedRow.ckmc"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="客户编号">
                <el-input v-model="selectedRow.khbh"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="送达方">
                <el-input v-model="selectedRow.songdf"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="售达方编号">
                <el-input v-model="selectedRow.sdfbh"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="售达方">
                <el-input v-model="selectedRow.shoudf"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="交货项目">
                <el-input v-model="selectedRow.jhxm"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="化验扣重">
                <el-input v-model="selectedRow.hykz"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="化验加罚扣重">
                <el-input v-model="selectedRow.hyjfkx"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <!-- 第二行 -->
            <el-col :span="3">
              <el-form-item label="预置扣重">
                <el-input v-model="selectedRow.yzkz"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="出场扣重">
                <el-input v-model="selectedRow.cckz"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="预置重量">
                <el-input v-model="selectedRow.yzzl"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="订单项目编号">
                <el-input v-model="selectedRow.ddxmbh"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="自产证明">
                <el-input v-model="selectedRow.zczm"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="矿商">
                <el-input v-model="selectedRow.zcks"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="煤种">
                <el-input v-model="selectedRow.zcmz"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="原始单号">
                <el-input v-model="selectedRow.ddysdh"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <!-- 第二行 -->
            <el-col :span="3">
              <el-form-item label="原始重量">
                <el-input v-model="selectedRow.ddyszl"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="NL煤炭备注1">
                <el-input v-model="selectedRow.nlmtbz1"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="NL煤炭备注2">
                <el-input v-model="selectedRow.nlmtbz2"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="粮食性质">
                <el-input v-model="selectedRow.orclgl"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="卡号">
                <el-input v-model="selectedRow.cardId"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="临时车牌">
                <el-input v-model="selectedRow.lscp"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="预发吨位">
                <el-input v-model="selectedRow.ddwlsl"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="规格">
                <el-input v-model="selectedRow.guige"></el-input>
              </el-form-item>
            </el-col>
          </el-row>

          <el-row :gutter="20">
            <!-- 第二行 -->
            <el-col :span="3">
              <el-form-item label="过磅类型">
                <el-input v-model="selectedRow.gblx"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <!-- 第二行 -->
            <el-col :span="3">
              <el-form-item label="小于200出场">
                <el-checkbox
                  v-model="selectedRow.ht_yccl_yc_kg"
                  :true-label="1"
                  :false-label="0"
                >
                </el-checkbox>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="自主煤炭多车">
                <el-checkbox
                  v-model="selectedRow.zzmtbs"
                  :true-label="1"
                  :false-label="0"
                >
                </el-checkbox>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="重量浮动出场">
                <el-checkbox
                  v-model="selectedRow.ht_kgfdcc"
                  :true-label="1"
                  :false-label="0"
                >
                </el-checkbox>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="24小时进场">
                <el-checkbox
                  v-model="selectedRow.ershisibz"
                  :true-label="1"
                  :false-label="0"
                >
                </el-checkbox>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="吸潮标记">
                <el-checkbox
                  v-model="selectedRow.yc_jzcc"
                  :true-label="1"
                  :false-label="0"
                >
                </el-checkbox>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="超长车标记">
                <el-checkbox
                  v-model="selectedRow.yc_ccc"
                  :true-label="1"
                  :false-label="0"
                >
                </el-checkbox>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="退车重量超差">
                <el-checkbox
                  v-model="selectedRow.czqztc"
                  :true-label="1"
                  :false-label="0"
                >
                </el-checkbox>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="使用临时车牌">
                <el-checkbox
                  v-model="selectedRow.lscp_bj"
                  :true-label="1"
                  :false-label="0"
                >
                </el-checkbox>
              </el-form-item>
            </el-col>
            <el-col :span="3">
              <el-form-item label="原始重量出厂">
                <el-checkbox
                  v-model="selectedRow.ysjz_bj"
                  :true-label="1"
                  :false-label="0"
                >
                </el-checkbox>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <!-- 按钮行 -->
        <span slot="footer" class="dialog-footer">
          <el-row type="flex" justify="end">
            <el-button type="primary" @click="jibenxinxibaocun">保存</el-button>
            <el-button type="primary" @click="fpxinxichuli"
              >发票信息处理</el-button
            >
            <el-button type="primary" @click="piaojubuda">票据补打</el-button>
            <el-button type="primary" @click="handleConfirm"
              >数据返回化验</el-button
            >
            <el-button type="primary" @click="sanshujinchang"
              >删除已进场或待进场</el-button
            >
            <el-button type="primary" @click="zhuangtaihuitui"
              >过磅状态退回</el-button
            >
            <el-button type="primary" @click="handleConfirm"
              >复磅标记与取消</el-button
            >
            <el-button type="primary" @click="menjinzhuangtaixiugai"
              >门禁状态修改</el-button
            >
            <el-button type="primary" @click="zhuanyunbiaojiann"
              >转运标记与取消</el-button
            >
            <el-button type="primary" @click="chexiangchang">车厢长</el-button>
          </el-row>
        </span>
      </el-dialog>
      <el-dialog title="发票信息处理" :visible.sync="fapiaoVisible" width="90%">
        <el-form label-width="100px" :inline="true">
          <el-row :gutter="20">
            <!-- 第一行 -->
            <el-col :span="5">
              <el-form-item label="银行持卡人姓名:">
                <el-input v-model="selectedRow.yhckrxm"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="银行卡号:">
                <el-input v-model="selectedRow.yhkh"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="联系电话:">
                <el-input v-model="selectedRow.lxdh"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="发票编号:">
                <el-input v-model="selectedRow.fpbh"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="5">
              <el-form-item label="发票审核人:">
                <el-input v-model="selectedRow.fpshr"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="发票上传身份证号:">
                <el-input v-model="selectedRow.fpscsfzh"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="粮食性质(潮粮\干粮):">
                <el-input v-model="selectedRow.orclgl"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row type="flex" justify="end">
            <el-button type="primary" @click="fapiaobaocun">保存</el-button>
          </el-row>
        </el-form>
      </el-dialog>
      <el-dialog
        title="三豪车厢长"
        :visible.sync="chexiangchangVisible"
        width="90%"
      >
        <el-form label-width="100px" :inline="true">
          <el-row :gutter="20">
            <!-- 第一行 -->
            <el-col :span="5">
              <el-form-item label="车牌号:">
                <el-input v-model="sanhao.车牌号码"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="5">
              <el-form-item label="车厢长:">
                <el-input v-model="sanhao.车厢长度"></el-input>
              </el-form-item>
            </el-col>
            <el-button type="primary" @click="chexiangchangtinajia"
              >添加或修改</el-button
            >
            <el-button type="primary" @click="chexiangchangquxiao"
              >取消</el-button
            >
          </el-row>
        </el-form>
      </el-dialog>
      <el-dialog title="票据补打" :visible.sync="piaojuVisible" width="50%">
        <el-form label-width="100px" :inline="true">
          <el-row :gutter="20">
            <!-- 第一行 -->
            <el-row type="flex" >
              <el-button type="primary" @click="chumenzheng">出门证</el-button>
              <el-button type="primary" @click="cg_meitan">磅单</el-button>
              <!-- <el-button type="primary" @click="caiwuduihuan"
                >财务兑换票</el-button
              >
              <el-button type="primary" @click="bangdan">磅单</el-button>
              <el-button type="primary" @click="weibangdan">微磅单</el-button> -->
            </el-row>
          </el-row>
        </el-form>
      </el-dialog>
      <chumen ref="chumen"  :formData="selectedRow" ></chumen>
      <cg_meitan ref="cg_meitan" :formData="selectedRow"></cg_meitan>
    </div>
    <div class="pagination-container">
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import {
  deletedaijinchang,
  modifyStatus,
  selectByCzbh,
  selectchexianghcang,
  selectyccl,
  updategbztbyczbh,
  updateguozhong,
  zhuanyunbiaoji,
} from "@/api/system/Fdongbei/yccl";

import chumen from "../bangdan/chumenzheng.vue";

import cg_meitan from "../bangdan/cg_meitan.vue";

export default {
  components: {
    chumen,
    cg_meitan
  },
  data() {
    return {
      value: false,
      tableData: [],
      dialogVisible: false,
      fapiaoVisible: false,
      chexiangchangVisible: false,
      piaojuVisible: false,
      selectedRow: {},
      datatab: [],
      sanhao: {},
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sql: "",
      },
      total: 0,
      form:{
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    chumenzheng(){
      this.$refs.chumen.select();

    },
    cg_meitan(){
      this.$refs.cg_meitan.select();
      // this.$refs.cg_meitan.code();
    },
    getList() {
      this.$modal.loading("查询中。。。");
      selectyccl(this.queryParams).then((response) => {
        this.tableData = response.rows;
        this.total = response.total;
        this.loading = false;
        this.$modal.closeLoading();
      });
    },
    jibenxinxibaocun() {
      updateguozhong(this.selectedRow).then((response) => {
        if (response.data > 0) {
          this.$modal.alert("修改成功");
          this.getList();
        } else {
          this.$modal.alertWarning("修改失败");
        }
      });
    },
    //发票信息处理
    fpxinxichuli() {
      this.fapiaoVisible = true;
    },
    fapiaobaocun() {
      updateguozhong(this.selectedRow).then((response) => {
        if (response.data > 0) {
          this.$modal.alert("修改成功");
          this.getList();
        } else {
          this.$modal.alertWarning("修改失败");
        }
      });
    },
    sanshujinchang() {
      deletedaijinchang({ czbh: this.selectedRow.czbh }).then((response) => {
        if (response.data > 2) {
          this.$modal.alert("删除成功");
        } else if (response.data === -1) {
          this.$modal.alertWarning("未查询到此车或此车状态不对");
        } else {
          this.$modal.alertWarning("删除失败");
        }
      });
    },
    //门禁状态修改
    menjinzhuangtaixiugai() {
      modifyStatus({ czbh: this.selectedRow.czbh }).then((response) => {
        this.$modal.msg(response.data);
      });
    },
    zhuangtaihuitui() {
      updategbztbyczbh({ czbh: this.selectedRow.czbh }).then((response) => {
        // console.log(response.data)

        this.$modal.msg(response.msg);
        this.getList();
      });
    },
    zhuanyunbiaojiann() {
      zhuanyunbiaoji({
        czbh: this.selectedRow.czbh,
        gbzt: this.selectedRow.gbzt,
      }).then((response) => {
        this.$modal.msg(response.msg);
        this.getList();
      });
    },
    handleRowDblClick(row, column, event) {
      selectByCzbh({ czbh: row.czbh }).then((response) => {
        this.selectedRow = response.data;
        // 显示对话框
        this.dialogVisible = true;
      });
    },
    chexiangchang() {
      selectchexianghcang({ czbh: "DR2412190002" }).then((response) => {
        this.sanhao = response.data;
      });
      this.chexiangchangVisible = true;
    },
    chexiangchangquxiao() {
      this.chexiangchangVisible = false;
    },
    chexiangchangtinajia() {},
    handleConfirm() {
      // 处理确定按钮的逻辑
      this.dialogVisible = false;
      // 可以在这里添加其他处理逻辑
    },
    piaojubuda(){
      this.piaojuVisible = true;
    }
  },
};
</script>

<style scoped lang="scss">
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 90vh; /* 使容器至少占满整个视口高度 */
}

.content {
  flex: 1; /* 使主要内容区域占据尽可能多的空间 */
}

.pagination-container .el-pagination {
  width: 100%;
}

.pagination-container {
  display: flex;
  width: 78%;
  justify-content: center; /* 水平居中 */
  align-items: center; /* 垂直居中 */
  padding: 16px; /* 可选，根据需要调整间距 */
  background-color: #ffffff; /* 可选，根据需要调整背景色 */
}
</style>
